import { applyMiddleware, createStore } from 'redux'
import reducer from './reducers'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunk, { ThunkAction } from 'redux-thunk'
import { TodoList } from './reducers/todos'
// const store = createStore(reducer, composeWithDevTools())
const store = createStore(reducer, composeWithDevTools(applyMiddleware(thunk)))

console.log( store.getState() )
// export  type XX = {
//     todos: {id:number,name:string,isDone:boolean}[],
// }

export type RootState = ReturnType<typeof store.getState>

// 类型参数1： ReturnType 用于指定函数的返回值类型 void
// 类型参数2： 指定RootState的类型
// 类型参数3： 指定额外的参数类型，一般为unkonwn或者any
// 类型参数4： 用于指定dispatch的Action类型
export type RootAction = ThunkAction<void, RootState, unknown, TodoAction>

export type TodoAction = 
    {type: 'todos/del', payload: number } | 
    {type: 'todos/add', name: string } | 
    {type: 'todos/update', id: number } |
    {type: 'todos/init', playload: TodoList }

export default store
